/*用户列表*/

layui.use('table', function(){
    var table = layui.table;
    table.render({
        id:"jobForm",
        elem: '#jobForm',
        url:'getJob.html',
        method: 'POST', //方式
        page:{
            //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 1, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false //不显示尾页
        },
        cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        cols: [ [
            {type:'checkbox'},
            {field:'remark',   title: '名称', sort: true},
            {field:'status', title: '状态', sort: true,templet: '#statusTpl'},
            {field:'beanName',  title: '类名', sort: true},
            {field:'methodName',title: '方法名', sort: true},
            {field:'params',   title: '参数', sort: true},
            {field:'cronExpression', title: '表达式', sort: true},
        ] ]
    });
});
function add() {
    parent.layer.open({
        type: 2,
        title: '计划任务-新增',
        //title: false, //不显示标题
        shadeClose: true,
        skin: 'layui-layer-molv',
        shade: 0.8,
        area: ['30%', '77%'],
        content: ['sys/job/add.html','no'], //iframe的url
        end:function () {
            reloadTable("jobForm");
        }
    });
}
function edit(){
    var table = layui.table;
    var rows = table.checkStatus('jobForm'); //test即为基础参数id对应的值
    var id = rows.data[0].jobId;
    if(rows.data.length!=1){
        layer.msg('请选择一条数据');
        return false;
    }else {
        var url = 'sys/job/edit.html?jobId='+id;
        parent.layer.open({
            type: 2,
            title: '用户管理-编辑',
            shadeClose: true,
            skin: 'layui-layer-molv',
            shade: 0.8,
            area: ['30%', '77%'],
            content: [url,'no'], //iframe的url
            end:function () {
                reloadTable("jobForm");
            }
        });
    }
}


function del(){
    var table = layui.table;
    var rows = table.checkStatus('jobForm'); //test即为基础参数id对应的值
    var ids=[];
    if(rows.data.length<1){
        layer.msg('请选择一条数据');
        return false;
    }
    for(var i=0;i<rows.data.length;i++){
        var rowid = rows.data[i].jobId;
        ids.push(rowid);
    }

    //询问框
    layer.confirm('确认要删除用吗',{btn: ['确定','取消'],icon: 2,title:'删除计划任务',skin:'layui-layer-molv'},
        function(index){
            $.ajax({
                type: "POST",
                url:"delete.html",
                async: false,
                traditional:true,
                cache: false,
                dataType:"json",
                data:{'ids':ids},
                success:function (data) {
                    if(data.code == 0){
                        layer.close(index);
                        parent.layer.msg('删除成功');
                    }
                    if(data.code == 500){
                        layer.close(index);
                        parent.layer.msg("删除失败");
                    }
                    reloadTable("jobForm");
                }
            })
        }, function(){
        });
}

function search(){
    var remark = $("input[name='remark']").val();
    var beanName = $("input[name='beanName']").val();

    var table = layui.table;
    table.reload("jobForm", { //此处是上文提到的 初始化标识id
        where: {
            //key: { //该写法上文已经提到
            remark: remark,beanName:beanName
            //}
        }
    });
}

function configure() {
    var table = layui.table;
    var rows = table.checkStatus('jobForm');
    if(rows.data.length!=1){
        layer.msg('请选择一条数据');
        return false;
    }else{
        var id = rows.data[0].jobId;
    }
    var url = 'sys/user/configure.html?jobId='+id;
    parent.layer.open({
        title:'分配权限',
        type: 2,
        area: ['20%', '77%'],
        skin: 'layui-layer-rim', //加上边框
        content: [url,'no'], //iframe的url
        end:function () {
            reloadTable("jobForm");
        }
    });
}
